package com.happy.controller;

import com.happy.entity.AdminEntity;
import com.happy.service.IAdminService;
import com.happy.util.ResultBody;
import com.happy.util.StateEnum;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.servlet.http.HttpSession;

@RestController
@RequestMapping ("/admin")
@CrossOrigin (value = "*", maxAge = 3600)
public class AdminController {

    @Resource
    private IAdminService iAdminService;


    @RequestMapping ("/querySingle")
    public ResultBody<AdminEntity> querySingle ( @RequestBody AdminEntity adminEntity, HttpSession session ) {
        AdminEntity admin = iAdminService.querySingle ( adminEntity );
        if ( admin != null ) {
            session.setAttribute ( "token", admin.getToken () );
            return ResultBody.success ( admin );
        }
        return ResultBody.fail ( StateEnum.RESULT_NULL_EXCE );
    }

}
